home *** CD-ROM | disk | FTP | other *** search
/ QuickTime for the Web (2nd Edition) / QuickTime for the Web (2nd Edition).iso / pc / Demos / Mac / Matthew's Behaviors / Matthew'sMotionƒ / 3dBounce < prev    next >
Encoding:
INI File  |  2001-09-10  |  2.0 KB  |  61 lines

  1. [Name]
  2. 3DBounce - From Matthew's Motion Suite.
  3. By Matthew Peterson, matthew@pinoko.berkeley.edu
  4.  
  5. [Description]
  6. 2-19-2000
  7. Drop this on a sprite, and it will bounce around the sprite
  8. track, scaling with perspective as it also bounces in
  9. the third dimension.
  10.  
  11. [Parameters]
  12.  
  13.  
  14. [Frame loaded]
  15. SpriteVars MP_dbouncestep MP_dbouncedeltax MP_dbouncedeltay MP_dbouncedirection
  16.  
  17. MP_dbouncedeltax = 3
  18. MP_dbouncedeltay = 5
  19. MP_dbouncestep = 1
  20. MP_dbouncedirection = 0.5
  21.  
  22.  
  23. [Idle]
  24. SpriteVars MP_dbouncestep MP_dbouncedeltax MP_dbouncedeltay MP_dbouncedirection
  25. LocalVars tempcenterx tempcentery tempscalefactor 
  26. //3D Bounce By Matthew Peterson
  27. //It is common to have a sprite bounce around the track
  28. //but why not add a third dimension. This sprite bounces
  29. //on the walls as well as in and out against an invisible
  30. //floor. A simple parabolic scaling is used to simulate
  31. //Depth.
  32. IF(MP_dbouncestep < 9)
  33.     //Remember the center position so we can restore it.
  34.     tempcenterx = (BoundsLeft + BoundsRight)/2
  35.     tempcentery = (BoundsTop + BoundsBottom)/2
  36.     //See if we are out of bounds so that we can change direction
  37.     if(boundsright > trackwidth)
  38.         MP_dbouncedeltax = - Abs(MP_dbouncedeltax)
  39.     elseif(boundsleft < 0)
  40.         MP_dbouncedeltax = Abs(MP_dbouncedeltax)
  41.     endif
  42.     if(boundsbottom > trackheight)
  43.         MP_dbouncedeltay = - Abs(MP_dbouncedeltay)
  44.     elseif(boundstop< 0)
  45.         MP_dbouncedeltay = Abs(MP_dbouncedeltay)
  46.     endif
  47.     //Undo scaling with a resetmatrix call
  48.     resetmatrix
  49.     //Calculate parabola
  50.     tempscalefactor = 1 - MP_dbouncestep*MP_dbouncestep/100
  51.     scale(tempscalefactor,tempscalefactor)//scale then
  52.     //Restore position with an added movement.
  53.     MoveBy(tempcenterx-(BoundsLeft + BoundsRight)/2 + MP_dbouncedeltax ,MP_dbouncedeltay + tempcentery - (BoundsTop + BoundsBottom)/2)
  54.     //Increase the step
  55.     MP_dbouncestep = MP_dbouncestep + MP_dbouncedirection
  56.     // If we hit the ground, or reach zero 3d velocity reverse step
  57.     if(MP_dbouncestep = 9 or MP_dbouncestep = -1)
  58.         MP_dbouncedirection = -MP_dbouncedirection
  59.         MP_dbouncestep = MP_dbouncestep + MP_dbouncedirection* 2
  60.     endif
  61. ENDIF